package com.example.lyl.yuejian.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lyl.yuejian.R;
import com.example.lyl.yuejian.bean.ClubLvBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by dllo on 18/3/23.
 */

public class ClubLvAdapter extends BaseAdapter {
    ClubLvBean clubLvBean;

    public void setClubLvBean(ClubLvBean clubLvBean) {
        this.clubLvBean = clubLvBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (clubLvBean == null) {
            return 0;
        } else {
            return clubLvBean.getData().size();
        }
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_clublv, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(parent.getContext()).load("http://" + clubLvBean.getData().get(position).getCpic()).placeholder(R.mipmap.lunbo1).into(holder.clubIv);
        holder.clubnameTv.setText(clubLvBean.getData().get(position).getCname());
        holder.gzsTv.setText(clubLvBean.getData().get(position).getAttentionCount() + "");
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.club_iv)
        ImageView clubIv;
        @BindView(R.id.clubname_tv)
        TextView clubnameTv;
        @BindView(R.id.gzs_tv)
        TextView gzsTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
